﻿using System;
using System.Text;
using TI_BLE_HCI_ClientLib.BaseEntities;
using TI_BLE_HCI_ClientLib.GenericHCIEntities;
using TI_BLE_HCI_ClientLib.HCIBaseEntities;

namespace TI_BLE_HCI_ClientLib.HCICommands
{
    public class HCICommand_GATT_Read_Characteristic_Value_Response : HCIVendorSpecificCommand
    {
        private const byte CMD = 0x0B;

        public HCICommand_GATT_Read_Characteristic_Value_Response(ushort connHandle, byte[] value)
            : base(HCIVendorSpecificCommandCSG.ATT, CMD)
        {
            var pars = new BaseEntityParameter[2];

            pars[0] = new WordParameter(connHandle);
            pars[1] = new ByteArrayParameter(value);

            base.addParameters(pars);
        }

        public HCICommand_GATT_Read_Characteristic_Value_Response(ushort connHandle, byte value)
            : this(connHandle, new byte[] { value }) { }

        public HCICommand_GATT_Read_Characteristic_Value_Response(ushort connHandle, ushort value)
            : this(connHandle, new byte[] { (byte)(value & 0xFF), (byte)((value >> 8) & 0xFF) }) { }

        public HCICommand_GATT_Read_Characteristic_Value_Response(ushort connHandle, string value)
            : this(connHandle, Encoding.UTF8.GetBytes(value)) { }
    }
}
